package com.zb.mobile.controller;

import com.zb.entity.AccounLoginInfo;
import com.zb.entity.FactorySelectVo;
import com.zb.entity.GoodsSpecInfoVo;
import com.zb.entity.SelectVo;
import com.zb.exception.VendorIdentifierException;
import com.zb.mobile.service.MobileSelectService;
import com.zb.network.service.ConNetworkAuthenFieldService;
import com.zb.result.PageUtil;
import com.zb.result.Result;
import com.zb.select.service.OrderSelecService;
import com.zb.service.*;
import com.zb.utils.TokenMobileUtil;
import com.zb.utils.TokenUserUtil;
import com.zb.utils.TokenUtil;
import com.zb.vo.OrderGoodsSelectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @Author WEN
 * @Date 2023/11/8 0008
 **/
@Api(tags = "移动端下拉数据类接口")
@RestController
@RequestMapping("/mobile/select")
public class MobileSelectController {
    @Resource
    private MobileSelectService mobileSelectService;
    @Resource
    private ZjProductService productService;
    @Resource
    private ZjWorkModuleService workModuleService;
    @Resource
    private ZjWorkModuleFieldService workModuleFieldService;
    @Resource
    private ConNetworkAuthenFieldService conNetworkAuthenFieldService;
    @Resource
    private ZjNetworkFieldService networkFieldService;
    @Resource
    private ZjNetworkEmpFieldService networkEmpFieldService;
    @Resource
    private ZjWorkFeeProjectService workFeeProjectService;
    @Resource
    private OrderSelecService orderSelecService;
    @Resource
    private ZjNetworkEmpBandService networkEmpBandService;

    @ApiOperation("获取商品品牌列表")
    @PostMapping("/getBrandList")
    public Result getBrandList(HttpServletRequest request, @RequestBody FactorySelectVo selectVo) throws VendorIdentifierException {
        Long custAccId = TokenMobileUtil.getCustAccId(request);
        if (null == custAccId) {
            custAccId = TokenUserUtil.getCustAccIdByMobildUserCustCode(request);
        }
        return Result.success().data(productService.pageMobileGoodsBrandSelect(custAccId, selectVo));
    }

    @ApiOperation("获取商品分类列表")
    @PostMapping("/getGoodstypeList")
    public Result getGoodstypeList(HttpServletRequest request, @RequestParam(required = false) @ApiParam(value = "品牌ID") Long brandId, @RequestBody FactorySelectVo selectVo) throws VendorIdentifierException {
        Long custAccId = TokenMobileUtil.getCustAccId(request);
        return Result.success().data(productService.pageMobileGoodsTypeSelect(custAccId, brandId, selectVo));
    }

    @ApiOperation("获取报单商品列表")
    @PostMapping("/getOrderGoodsList")
    public Result getOrderGoodsList(HttpServletRequest request, @RequestBody OrderGoodsSelectVo goodsSelectVo) throws VendorIdentifierException {
        Long custAccId = TokenMobileUtil.getCustAccId(request);
        return Result.success().data(mobileSelectService.getGoodsList(custAccId, goodsSelectVo));
    }

    @ApiOperation("获取所有报单模块下拉列表")
    @PostMapping("/getOrderModuleList")
    public Result getOrderModuleList(HttpServletRequest request, @RequestParam(required = false) @ApiParam(value = "品牌商家ID") Long factoryId) throws VendorIdentifierException {
        Long custAccId = TokenMobileUtil.getCustAccId(request);
        return Result.success().data(PageUtil.rows(workModuleService.getOrderModuleListSelect(custAccId, factoryId)));
    }

    @ApiOperation("根据模块ID获取模块详情")
    @GetMapping("/getOrderModule/{id}")
    public Result getOrderModule(@PathVariable @ApiParam(value = "模块ID", required = true) Long id) {
        return Result.success().data(PageUtil.row(workModuleService.getMobileOrderModule(id)));
    }

    @ApiOperation("根据模块ID获取工单自定义字段")
    @GetMapping("/getModuleField/{moduleId}")
    public Result getModuleField(@PathVariable @ApiParam(value = "模块ID", required = true) Long moduleId) {
        return Result.success().data(PageUtil.rows(workModuleFieldService.getModuleField(true, moduleId)));
    }

    @ApiOperation("获取服务商团队认证自定义字段")
    @GetMapping("/getNetworkTeamAuthenField")
    public Result getNetworkTeamAuthenField(HttpServletRequest request) throws VendorIdentifierException {
        Long custAccId = TokenMobileUtil.getCustAccId(request);
        return Result.success().data(PageUtil.rows(conNetworkAuthenFieldService.getNetworkAuthenField(1, custAccId)));
    }

    @ApiOperation("获取服务商个人认证自定义字段")
    @GetMapping("/getNetworkAloneAuthenField")
    public Result getNetworkAloneAuthenField(HttpServletRequest request) throws VendorIdentifierException {
        Long custAccId = TokenMobileUtil.getCustAccId(request);
        return Result.success().data(PageUtil.rows(conNetworkAuthenFieldService.getNetworkAuthenField(2, custAccId)));
    }

    @ApiOperation("获取工程师认证自定义字段")
    @GetMapping("/getNetworkEmpAuthenField")
    public Result getNetworkEmpAuthenField(HttpServletRequest request) throws VendorIdentifierException {
        Long custAccId = TokenMobileUtil.getCustAccId(request);
        return Result.success().data(PageUtil.rows(conNetworkAuthenFieldService.getNetworkAuthenField(3, custAccId)));
    }

    @ApiOperation("获取工程师自定义字段")
    @GetMapping("/getNetworkEmpFields")
    public Result getNetworkEmpCustomFields(HttpServletRequest request) throws VendorIdentifierException {
        Long custAccId = TokenMobileUtil.getCustAccId(request);
        return Result.success("获取工程师自定义字段成功").data(PageUtil.rows(networkEmpFieldService.getNetworkEmpCustomFields(custAccId, true)));
    }

    @ApiOperation("获取移动端工单服务费用下拉数据")
    @GetMapping("/getOrderServiceFeeSelect")
    public Result getMobileOrdeServiceFeeSelect(HttpServletRequest request) throws VendorIdentifierException {
        Long custAccId = TokenMobileUtil.getCustAccId(request);
        return Result.success().data(PageUtil.rows(workFeeProjectService.getMobileOrdeServiceFeeSelect(custAccId)));
    }

    @ApiOperation("获取移动端配件下拉数据")
    @PostMapping("/getMobileSpareSelect/{workId}")
    public Result getMobileSpareSelect(HttpServletRequest request, @PathVariable @ApiParam(value = "工单ID", required = true) Long workId, @RequestBody SelectVo selectVo) throws VendorIdentifierException {
        Long custAccId = TokenMobileUtil.getCustAccId(request);
        return Result.success("获取移动端配件下拉数据成功").data(orderSelecService.getOrderSparePageSelect(custAccId, workId, selectVo));
    }

    @ApiOperation("获取移动端配件规格下拉数据")
    @PostMapping("/getOrderSpareSpecSelect/{spareId}")
    public Result getMobileSpareSpecSelect(HttpServletRequest request, @PathVariable @ApiParam(value = "配件ID", required = true) Long spareId, @RequestBody SelectVo selectVo) throws VendorIdentifierException {
        Long custAccId = TokenMobileUtil.getCustAccId(request);
        return Result.success("获取移动端配件规格下拉数据成功").data(orderSelecService.getOrderSpareSpecSelect(custAccId, spareId, selectVo));
    }

    @ApiOperation("获取银行卡下拉数据")
    @GetMapping("/getNetworkEmpBandSelect")
    public Result getMobileNetworkEmpBandSelect(HttpServletRequest request) {
        AccounLoginInfo loginInfo = TokenMobileUtil.getAccountLoginInfo(request);
        return Result.success("获取银行卡下拉数据成功").data(PageUtil.rows(networkEmpBandService.getNetworkEmpBandSelect(loginInfo.getNetworkEmpId())));
    }

    @ApiOperation("根据工单模块ID获取模块信息")
    @GetMapping("/getWorkModule/{moduleId}")
    public Result getWorkModule(@PathVariable @ApiParam(value = "工单模块ID", required = true) Long moduleId) {
        return Result.success("获取模块信息成功").data(PageUtil.row(workModuleService.getMobileOrderModule(moduleId)));
    }

    @ApiOperation("根据商品ID&商品规格ID获取商品信息")
    @GetMapping("/getGoodsInfo/{goodsId}/{goodsSpecId}")
    public Result getGoodsInfo(@PathVariable @ApiParam(value = "商品ID", required = true) Long goodsId,
                               @PathVariable @ApiParam(value = "商品规格ID", required = true) Long goodsSpecId) {
        return Result.success("获取商品信息成功").data(PageUtil.row(productService.getGoodsByIdAndSpecId(goodsId, goodsSpecId)));
    }

    @ApiOperation("根据商品id获取商品规格")
    @GetMapping("/getGoodsSpec/{goodsId}")
    public Result getGoodsSpec(@PathVariable @ApiParam(value = "商品ID", required = true) Long goodsId) {
        List<GoodsSpecInfoVo> data = productService.getSpecByGoodsId(goodsId);
        return Result.success("获取商品规格成功").data(PageUtil.row( data));
    }
}
